// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 * Description: perf tools
 * Author: Huawei Technologies Co., Ltd
 * Create: 2022-05-31
 */
#ifndef __DFX_PERF_TOOLS_H
#define __DFX_PERF_TOOLS_H
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/types.h>
#include <linux/version.h>
#define PROC_PERF_TOOLS_DIR_NAME "perf"
#define DFX_PERF_CMD_SIZE	8

extern int __init init_perf_sched(struct proc_dir_entry *perf_dir);
extern void __exit exit_perf_sched(void);

#define DEFINE_PROC_ATTRIBUTE(name, __write)				\
	static int name##_open(struct inode *inode, struct file *file)	\
	{								\
		return single_open(file, name##_show, PDE_DATA(inode));	\
	}								\
									\
	static const struct proc_ops name##_ops = {			\
		.proc_open	= name##_open,				\
		.proc_read	= seq_read,				\
		.proc_write	= __write,				\
		.proc_release	= single_release,			\
	}

#define DEFINE_PROC_ATTRIBUTE_RW(name)					\
	static ssize_t name##_write(struct file *file,			\
				    const char __user *buf,		\
				    size_t count, loff_t *ppos)		\
	{								\
		return name##_store(PDE_DATA(file_inode(file)), buf,	\
				    count);				\
	}								\
	DEFINE_PROC_ATTRIBUTE(name, name##_write)

#define DEFINE_PROC_ATTRIBUTE_RO(name)	\
	DEFINE_PROC_ATTRIBUTE(name, NULL)

#endif
